using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace Graph
{
    /// <summary>
    /// Represents a collection of nodes
    /// </summary>
    /// <typeparam name="T">The type of object contained in the nodes</typeparam>
    
    public class NodeList<T> : Collection<Node<T>> //inheriting from the Collection class allows us to represent our nodes as a collection - perfect
    {

        #region Constructors

        /// <summary>
        /// Initializes an empty node list
        /// </summary>
        
        public NodeList()
            : base()
        {
        }

        /// <summary>
        /// Initializes a node list and sets its size
        /// </summary>
        /// <param name="size">The number of nodes in the node list</param>
        
        public NodeList(int size)
        {
            //add nodes to the collection of nodes
            for (int i = 0; i < size; i++)
            {
                base.Items.Add(default(Node<T>));
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Check to see if a value exists in the node list - if it does, it returns the value, otherwise, returns null.
        /// </summary>
        /// <param name="value">The value to be found</param>
        /// <returns>If the value is found in the list, it is returned, otherwise, null is returned.</returns>
        
        public Node<T> FindByValue(T value)
        {
            foreach (Node<T> node in Items)
            {
                if (node.Value.Equals(value))
                {
                    return node;
                }
            }
            return null; //no match found :(
        }

        #endregion;
    } 
}
